<%@ page language="java" pageEncoding="utf-8" contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="ww" uri="webwork" %>
<!-- form id必须命名为selectUserForm -->
<form class="form-horizontal form-validate" method="post" id="selectUserForm" name="selectUserForm" action="wfSend.action" 
	onsubmit="return pfm_wfsubmit(this);" style="width: 600px;">
	<input type="hidden" name="postId" id="postId" value="<ww:property value='postId'/>">
	<input type="hidden" name="mulIds" id="mulIds">
	
	<div id="pfm_u1" style="display: inline-block; width: 300px; overflow-y: scroll; overflow-x: auto; height:380px;">
		<ul id="userTree" class="ztree" style="margin-top: 20px;"></ul>
	</div>

	<div style="display: inline-block; width: 290px; height: 330px;">
		<label>提示：双击则移除被选项</label>
	  	<select multiple id="select2" style="display: block; width:100%; height:100%; overflow:auto; border: 0;"></select>
	</div>

	<div class="set-btn" data-spy="affix" data-offset-top="200">
		<a class="btn" href="javascript:;" id="removeAll">清空</a>
		<a class="btn green" href="javascript:;" onclick="savePostUser();">保存</a>
		<a class="btn reset" href="javascript:;" onclick="$css.closeDialog();">取消</a>
	</div>
</form>
<script type="text/javascript">
function savePostUser() {
	var $d = $css.focusDialog();
	var $options = $('#select2 option', $d);
	var all="";
	$options.each(function() {
	    all += $(this).attr("value")+",";
	});
	$css.post('addPostUser.action', {
		'postId': $('#postId', $d).val(),
		'mulIds': all
	}, function (data) {
		if (0 === data.result) {
			$css.closeDialog();
			$navTab.refreshCurrentTab();
			$css.tip(data.msg);
		} else {
			$css.alert(data.msg);
		}
	}, 'json');
}
using(['tree', 'selectUser'], function () {
	
	var user_setting = {
			view : {
				dblClickExpand : false
			},
			data : {
				simpleData : {
					enable : true
				}
			},
			callback : {
				onClick : userClick
			}
		};
	
	function userClick(event, treeId, node) {
		var tree = $.fn.zTree.getZTreeObj(treeId);
		if ('user' === node.type) {
			$selectUser.select(node.id, node.name);
		} else {
			if(node.open) {
				tree.expandNode(node, false);
			} else {
				tree.expandNode(node, true);
			}
			tree.cancelSelectedNode(node);
		}
	}
	var userNode = <ww:property value="result" />
	$.fn.zTree.init($("#userTree"), user_setting, userNode);
	$selectUser.init();
})

</script>
